package com.lzb.watermarkcamera.adapter;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.watermarkcamera.R;
import com.lzb.watermarkcamera.basic.ProviderMultiAdapter;
import com.lzb.watermarkcamera.bean.PhoneAlbumBean;

import org.jetbrains.annotations.NotNull;

public class PhoneAlbumAdapter extends ProviderMultiAdapter<PhoneAlbumBean> {

    private boolean isEdit;

    public PhoneAlbumAdapter() {
        addItemProvider(new PhoneAlbumItemProvider());
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class PhoneAlbumItemProvider extends BaseItemProvider<PhoneAlbumBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_phone_album;
        }

        @Override
        public void convert(@NotNull BaseViewHolder baseViewHolder, PhoneAlbumBean phoneAlbumBean) {
            baseViewHolder.setText(R.id.tvPhoneAlbumTime, phoneAlbumBean.getTime());
            baseViewHolder.setText(R.id.tvPhoneAlbumSize, "（" + phoneAlbumBean.getClassBeanList().size() + "）");

            if (phoneAlbumBean.isSelected()) {
                baseViewHolder.setImageResource(R.id.ivPhoneAlbumSelector, R.drawable.axz2);
            } else {
                baseViewHolder.setImageResource(R.id.ivPhoneAlbumSelector, R.drawable.awxz);
            }

            baseViewHolder.setGone(R.id.llPhoneAlbumSelector, !isEdit);

            RecyclerView rvPhoneAlbumChild = baseViewHolder.getView(R.id.rvPhoneAlbumChild);
            rvPhoneAlbumChild.setLayoutManager(new GridLayoutManager(getContext(), 3));
            AlbumChildAdapter albumChildAdapter = new AlbumChildAdapter();
            rvPhoneAlbumChild.setAdapter(albumChildAdapter);
            albumChildAdapter.setEdit(isEdit);
            albumChildAdapter.setPhoneAlbumBean(phoneAlbumBean);
            albumChildAdapter.setList(phoneAlbumBean.getClassBeanList());
            albumChildAdapter.setOnItemClickListener(getOnItemClickListener());
            albumChildAdapter.setOnItemLongClickListener(getOnItemLongClickListener());
        }
    }
}
